package winter_vacation_homework.day_11;

/**
 * 【LeetCode题号: 35. 搜索插入位置】
 * https://leetcode-cn.com/problems/search-insert-position/
 */
public class SearchInsertLocation {
    public int searchInsert(int[] nums, int target) {
        if(nums[0] >= target){
            return 0 ;
        }

        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > target){
                if(nums[i - 1] == target){
                    return i - 1;
                }else{
                    return i;
                }
            }
        }
        if(nums[nums.length - 1] == target){
            return nums.length - 1;
        }else{
            return nums.length;
        }

    }
}
